//
//  DetailedViewController.m
//  CarHome
//
//  Created by 王建男 on 14-9-22.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "DetailedViewController.h"
#import "UIImageView+WebCache.h"
#import "OneSellTableViewCell.h"
#import "OneSellfirstTableViewCell.h"
#import "DealerListModel.h"
#import "DealerDetailModel.h"
#import "MapViewController.h"
#import "PictureCellTableViewCell.h"
#import "EquipMentModel.h"
#import "ParamitemsEquipMent.h"
#import "PraiseTableViewCell.h"
#import "DownButton.h"
#import "CityView.h"
#import "CityIdModel.h"
#import "AlbumVC.h"

@interface DetailedViewController ()
{
    CGRect initialFrame;
    CGFloat defaultViewHeight;
    CGFloat defaultviewWidth;
}
@end

// 重用池

NSString *const TableViewCellIdentifier_detailed = @"Cell_FindCar_detailed";
NSString *const TableViewCellIdentifier_First = @"Cell_FindCar_First";
NSString *const TableViewCellIdenttifier_Picture = @"Cell_FindCar_Picture";
NSString *const TableViewCellIdenttifier_EquipMent = @"Cell_FindCar_EquipMent";
NSString *const TableViewCellIdenttifier_Praise = @"Cell_FindCar_Praise";

@implementation DetailedViewController

- (void)dealloc
{
    [_tableView release];
    [_tableViewArray release];
    
    [_image release];
    [_down release];
    [_moDel release];
    [_titleLabel release];
    
    [_picture release];
    [_equipment release];
    
    [_pictureArray release];
    [_pictureView release];
    [_praise release];
    
    [_equipMentView release];
    [_equipMentArray release];
    
    [_praiseView release];
    [_praiseArray release];
    [_praiseLabel_prt release];
    [_praiseLabel_per release];
    
    _tableView = nil;
    _tableViewArray = nil;
    
    _image = nil;
    _down = nil;
    _moDel = nil;
    _picture = nil;
    _equipment = nil;
    _praise = nil;
    
    _pictureView = nil;
    _pictureArray = nil;
    
    _equipMentArray = nil;
    _equipMentView = nil;
    
    _titleLabel = nil;
    
    _praiseView = nil;
    _praiseArray = nil;
    _praiseLabel_per = nil;
    _praiseLabel_prt = nil;
    
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        // Custom initialization
        _tableViewArray = [[NSMutableArray alloc] init];
        _pictureArray = [[NSMutableArray alloc] init];
        _equipMentArray = [[NSMutableArray alloc] init];
        _praiseArray = [[NSMutableArray alloc] init];
        
        self.urlStr = [[NSMutableString alloc] initWithFormat:@"%@", SellCar];
        _piece = @"110100";
        _cityName = @"北京";
        
        
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path = [paths firstObject];
        path = [NSString stringWithFormat:@"%@/%@", path, @"city.plist"];
        
        NSMutableArray *citys = [NSMutableArray arrayWithContentsOfFile:path];
        
        //设置初始城市
        
        if ([citys count] != 0) {
            [_urlStr replaceOccurrencesOfString:_piece withString:[NSString stringWithFormat:@"%@",[citys firstObject]] options:NSCaseInsensitiveSearch range:NSMakeRange(0, [_urlStr length])];
            
            _piece = [[NSString alloc] initWithFormat:@"%@", [citys firstObject]];
            
            _cityName = [[NSString alloc] initWithFormat:@"%@", [citys lastObject]];
            
        }
        //存储网络连接用于加载
        
        self.pictureUrl = [[NSMutableString alloc] initWithFormat:@"%@", Picture];
        self.equipMentUrl = [[NSMutableString alloc] initWithFormat:@"%@", Equipment];
        self.praiseUrl = [[NSMutableString alloc] initWithFormat:@"%@", Praise];
        
        
        _moDel = [[DealerDetailModel alloc] init];
        
        [_urlStr release];
        [_pictureUrl release];
        [_equipment release];
        [_praiseUrl release];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    // Do any additional setup after loading the view.
    
   
    
    [self creatDown];
    [self creatPicture];
    [self createquipment];
    [self creatpraise];
    
    self.view.backgroundColor = myColor_dark;
    
    _scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height)];
    [_scroll setContentSize:CGSizeMake(self.view.frame.size.width * 4, 0)];
    _scroll.delegate = self;
    [_scroll addSubview:_down];
    [_scroll addSubview:_picture];
    [_scroll addSubview:_equipment];
    [_scroll addSubview:_praise];
    
    [_scroll setPagingEnabled:YES];
    _scroll.backgroundColor = myColor_dark;
    [self.view addSubview:_scroll];
    
    UIView *background = [[UIView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 49)];
    background.backgroundColor = myColor_dark;
    [self.view addSubview:background];
    
    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, self.view.frame.size.width - 125, 49)];
    [_titleLabel setText:_top_title];
    _titleLabel.backgroundColor = myColor_dark;
    [_titleLabel setNumberOfLines:2];
    [_titleLabel setTextAlignment:NSTextAlignmentCenter];
    _titleLabel.textColor = [UIColor whiteColor];
    [background addSubview:_titleLabel];
    
    [background release];
    // 返回
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(5, 10, 25, 25)];
    [button setImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [background addSubview:button];
    
    //城市
    
    _rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [_rightButton setFrame:CGRectMake(self.view.frame.size.width - 73, 5, 75, 40)];
    [_rightButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [_rightButton.titleLabel setNumberOfLines:2];
    
    [_rightButton setTitle:_cityName forState:UIControlStateNormal];
    [_rightButton setImage:[UIImage imageNamed:@"DrawerButton.png"] forState:UIControlStateNormal];
    [_cityName release];
    
    [_rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_rightButton addTarget:self action:@selector(cityAction:) forControlEvents:UIControlEventTouchUpInside];
    [background addSubview:_rightButton];
    
    [_scroll release];
    
    _downButtn = [[DownButton alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 40, self.view.frame.size.width, 40)];
    
    //添加下部四个按钮添加点击事件
    
    [_downButtn.button_table addTarget:self action:@selector(downbuttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [_downButtn.button_picture addTarget:self action:@selector(downbuttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [_downButtn.button_equipment addTarget:self action:@selector(downbuttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [_downButtn.button_praise addTarget:self action:@selector(downbuttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_downButtn];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(recieve:) name:@"chengshi" object:nil];
}

#pragma mark -
#pragma mark 消息中心接收

- (void)recieve:(NSNotification *)object
{
    /****************************
    1.获取点击城市
    2.网址拼接 获取网络请求
    3.将城市存入本地
    ****************************/
    
    CityIdModel *model = object.object;
    
    NSString *city = [NSString stringWithFormat:@"%ld", (long)model.cityId];
    
    [_urlStr replaceOccurrencesOfString:_piece withString:city options:NSCaseInsensitiveSearch range:NSMakeRange(0, [_urlStr length])];
    
    [_piece release];
    
    _piece = [[NSString alloc] initWithFormat:@"%ld", (long)model.cityId];
    
    [_rightButton setTitle:model.cityname forState:UIControlStateNormal];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths firstObject];
    path = [NSString stringWithFormat:@"%@/%@", path, @"city.plist"];
    
    NSMutableArray *citys = [NSMutableArray arrayWithObjects:[NSNumber numberWithInteger:model.cityId], model.cityname, nil];
    [citys writeToFile:path atomically:YES];
    
    [self connect_Sell:_urlStr];
}

#pragma mark -
#pragma mark 界面切换点击事件

- (void)downbuttonAction:(UIButton *)sender
{
    [_scroll setContentOffset:CGPointMake(self.view.frame.size.width * sender.tag, 0)];
    [_downButtn setchangeView:sender.tag * 80];
}

#pragma mark -
#pragma mark 城市

- (void)cityAction:(id)sender
{
    CityView *cityView = [[CityView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height + 59)];
    cityView.block = ^(){
        [cityView removeFromSuperview];
    };
    [self.view addSubview:cityView];
    [cityView release];
}

#pragma mark -
#pragma mark 创建界面一视图

- (void)creatDown
{
    _down = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 20)];
    _down.clipsToBounds = YES; //只显示frame内的内容
    _down.BackgroundColor = [UIColor whiteColor] ;
    
    _image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 240)];
    [_down addSubview:_image];
    
    initialFrame = _image.frame;
    defaultViewHeight = initialFrame.size.height;
    defaultviewWidth = initialFrame.size.width;
    
    [self creatTableView];
    
}

#pragma mark -
#pragma mark 创建界面二视图

- (void)creatPicture
{
    _picture = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height - 20)];
    [_picture setBackgroundColor:[UIColor whiteColor]];
    
    [self creatpictureTableView];
}

#pragma mark -
#pragma mark 创建界面三视图

- (void)createquipment
{
    _equipment = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * 2, 0, self.view.frame.size.width, self.view.frame.size.height - 20)];
    [_equipment setBackgroundColor:[UIColor whiteColor]];
    [self createquipmentTableView];
}

#pragma mark -
#pragma mark 创建界面四视图

- (void)creatpraise
{
    _praise = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * 3, 0, self.view.frame.size.width, self.view.frame.size.height - 20)];
    [_praise setBackgroundColor:[UIColor whiteColor]];
    _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 320, 200)];
    
    [_label setText:@"正在加载····"];
    [_label setTextAlignment:NSTextAlignmentCenter];
    
    [_label setTextColor:[UIColor blackColor]];
    [_praise addSubview:_label];
    
    [self createpraiseTableView];
    
    //耗油量
    
    _praiseLabel_prt = [[UILabel alloc] initWithFrame:CGRectMake(70, 75, 120, 20)];
    [_praiseLabel_prt setFont:[UIFont systemFontOfSize:17]];
    _praiseLabel_prt.textColor = myColor_dark;
    [_praise addSubview:_praiseLabel_prt];
    
    //参与测评人数
    
    _praiseLabel_per = [[UILabel alloc] initWithFrame:CGRectMake(188, 77, 120, 20)];
    [_praiseLabel_per setFont:[UIFont systemFontOfSize:12]];
    _praiseLabel_per.textColor = myColor_dark;
    [_praise addSubview:_praiseLabel_per];
}

- (void)buttonAction:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark -
#pragma mark creatTableView 界面一

- (void)creatTableView
{
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 90) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor clearColor];
    [_tableView registerClass:[OneSellTableViewCell class] forCellReuseIdentifier:TableViewCellIdentifier_detailed]; //卖家cell重用池
    
    [_tableView registerClass:[OneSellfirstTableViewCell class] forCellReuseIdentifier:TableViewCellIdentifier_First];
    
    [_down addSubview:_tableView];
}

#pragma mark -
#pragma mark pictureTableView 界面二

- (void)creatpictureTableView
{
    _pictureView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 104) style:UITableViewStylePlain];
    [_pictureView setSeparatorColor:[UIColor clearColor]];
    _pictureView.delegate = self;
    _pictureView.dataSource = self;
    _pictureView.backgroundColor = [UIColor clearColor];
    [_pictureView registerClass:[PictureCellTableViewCell class] forCellReuseIdentifier:TableViewCellIdenttifier_Picture]; //图片cell重用池
    
    [_picture addSubview:_pictureView];

}

#pragma mark -
#pragma mark equipmentTableView 界面三

- (void)createquipmentTableView
{
    _equipMentView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 105) style:UITableViewStylePlain];
    _equipMentView.delegate = self;
    _equipMentView.dataSource = self;
    _equipMentView.backgroundColor = [UIColor clearColor];
    [_equipment addSubview:_equipMentView];
    
}

#pragma mark -
#pragma mark creatpraiseTableView 界面四

- (void)createpraiseTableView
{
    _praiseView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 160) style:UITableViewStylePlain];
    [_praiseView setSeparatorColor:[UIColor clearColor]];
    _praiseView.delegate = self;
    _praiseView.dataSource = self;
    _praiseView.backgroundColor = [UIColor clearColor];
    [_praiseView registerClass:[PraiseTableViewCell class] forCellReuseIdentifier:TableViewCellIdenttifier_Praise]; //评分cell重用池
    
    [_praise addSubview:_praiseView];
    
}

#pragma mark -
#pragma mark tableview协议

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //通过tableview判断cell个数
    
    if (tableView == _tableView) {
        return [_tableViewArray count] + 1;
    }
    if (tableView == _pictureView) {
        return [_pictureArray count];
    }
    if (tableView == _equipMentView) {
        ParamitemsEquipMent *model = [_equipMentArray objectAtIndex:section];
        return [model.items count];
    }
    if (tableView == _praiseView) {
        return [_praiseArray count] / 2;
    }
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //如果为第三个页面 返回数组个数
    
    if (tableView == _equipMentView) {
        return [_equipMentArray count];
    } else {
        return 1;
    }
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    //返回section name
    
    if (tableView == _equipMentView) {
        if ([_equipMentArray count]) {
            ParamitemsEquipMent *model = [_equipMentArray objectAtIndex:section];
            return model.type;
            [model release];
        }
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //界面一
    if (tableView == _tableView) {
        if (indexPath.row == 0) {
            return 230;
        }
        return 140;
    }
    //界面二
    if (tableView == _pictureView) {
        return 110;
    }
    //界面三
    if (tableView == _equipMentView) {
        return 20;
    }
    //界面四
    if (tableView == _praiseView) {
        return 100;
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //判断tableview为那个页面
    
    if (tableView == _tableView) {
    if (indexPath.row >= 1) {
        OneSellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdentifier_detailed forIndexPath:indexPath];
        if ([_tableViewArray count]) {
            DealerListModel *model = [_tableViewArray objectAtIndex:(indexPath.row - 1)];
            [cell setOneSell:model];
        }
        return cell;
    } else {
        OneSellfirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdentifier_First forIndexPath:indexPath];
        [cell setdealer:_moDel];
        return  cell;
    }
  } else if (tableView == _pictureView) {
        PictureCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdenttifier_Picture forIndexPath:indexPath];
        [cell setImage:[_pictureArray objectAtIndex:indexPath.row]];
      
      //回调函数，调出图片浏览
      
      [cell sendReciveBlock:^{
          
          NSMutableString *urlstring = [NSMutableString stringWithFormat:@"%@", _pictureUrl];
          
          [urlstring replaceOccurrencesOfString:@"cg0" withString:[NSString stringWithFormat:@"cg%@", [[_pictureArray objectAtIndex:indexPath.row] objectForKey:@"id"]] options:NSCaseInsensitiveSearch range:NSMakeRange(0, [urlstring length])];
          
          AlbumVC *album = [[AlbumVC alloc] init];
    
          [album connectURL_picture:urlstring];
          [self presentViewController:album animated:NO completion:^{
          }];
          [album release];
          
      }];
      
        return cell;
      
  } else if (tableView == _equipMentView) {
      
      //界面三cell
      
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdenttifier_EquipMent];
      
      if (!cell) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:TableViewCellIdenttifier_EquipMent];
      }
      
      if ([_equipMentArray count]) {
          ParamitemsEquipMent *paramitems = [_equipMentArray objectAtIndex:indexPath.section];
          EquipMentModel *equipment = [paramitems.items objectAtIndex:indexPath.row];
          
          [cell.textLabel setFont:[UIFont systemFontOfSize:13]];
          [cell.textLabel setText:equipment.name];
          
          [cell.detailTextLabel setFont:[UIFont systemFontOfSize:13]];
          [cell.detailTextLabel setText:equipment.value];
      }
      
      return cell;
    
  } else if (tableView == _praiseView) {
      
      //界面四cell
      
      PraiseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableViewCellIdenttifier_Praise];
      
      NSInteger num = indexPath.row;
      num *= 2;
      
      [cell setgauge:[_praiseArray objectAtIndex:num]];
      [cell setgauge_1:[_praiseArray objectAtIndex:num + 1]];
      
      return cell;
  }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //判断是否为卖家cell
    if (tableView == _tableView) {
      if (indexPath.row != 0 ) {
          
          //如果数组不为空 切换地图
          
          if ([_tableViewArray count]) {
              DealerListModel *model = [_tableViewArray objectAtIndex:indexPath.row - 1];
              MapViewController *map = [[MapViewController alloc] init];
              [map setWebUrl:model.ion Andlat:model.lat Andname:model.shortName];
              [self presentViewController:map animated:YES completion:^{
                 [map release]; 
              }];
              
          }
      }
    }
}

#pragma mark -
#pragma mark 实现图片偏移放大缩小

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView == _tableView) {
    CGRect f = _image.frame;
    _image.frame = f;
    //偏移量小于-16 ， 实现图片放大缩小
    if(scrollView.contentOffset.y < -16) {
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        
        initialFrame.origin.y = offsetY * -1;
        initialFrame.origin.x = offsetY * -1 / 2 + 8;
        initialFrame.size.height = defaultViewHeight + offsetY - 16 ;
        initialFrame.size.width = defaultviewWidth   + offsetY - 16;
        _image.frame = initialFrame;
    }
    // 偏移量大于30 ， 图片随着tableview滚动
    if (scrollView.contentOffset.y > 30) {
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        
        initialFrame.origin.y = offsetY + 30 ;
        _image.frame = initialFrame;
    } else {
        
        //设置偏移量 ， 产生运动差
        
        CGFloat offsetY = (scrollView.contentOffset.y + scrollView.contentInset.top) * -1;
        
        initialFrame.origin.y = offsetY * 0.1;
        _image.frame = initialFrame;
          }
    }
}

#pragma mark -


- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    //通过偏移量 判断tableview获取网络请求
    //_downButton 设置偏移量
    
    if (_scroll.contentOffset.x == 0) { //第一页
        [_downButtn setchangeView:0];
    }
    if (_scroll.contentOffset.x == 320) { //第二页
        [self connect_Picture:_pictureUrl];
        [_downButtn setchangeView:80];
    }
    if (_scroll.contentOffset.x == 640) { //第三页
        [self connect_Equipment:_equipMentUrl];
        [_downButtn setchangeView:160];
    }
    if (_scroll.contentOffset.x == 960) { //第四页
        [self connect_Praise:_praiseUrl];
        [_downButtn setchangeView:240];
        
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//网址拼接

- (void)setConnect:(NSString *)carId AndSpe:(NSString *)specitem Andtitle:(NSString *)title
{
    //设置标题
    _top_title = title;
    
    //界面一网址拼接
    NSRange subStr = [_urlStr rangeOfString:@"sp00000"];
    NSRange subStrs = [_urlStr rangeOfString:@"ss0000"];
    if (subStrs.location != NSNotFound) {
        [_urlStr replaceCharactersInRange:subStrs withString:[NSString stringWithFormat:@"ss%@", specitem]];
    }
    if (subStr.location != NSNotFound) {
        [_urlStr replaceCharactersInRange:subStr withString:[NSString stringWithFormat:@"sp%@", carId]];
    }
    
    
    NSMutableString *_detailUrl = [NSMutableString stringWithFormat:@"%@", DetailCar];
    NSRange subStr_detail = [_detailUrl rangeOfString:@"s00000"];
    if (subStr_detail.location != NSNotFound) {
        [_detailUrl replaceCharactersInRange:subStr_detail withString:[NSString stringWithFormat:@"s%@", carId]];
    }
    
    //图片页网址拼接
    
    NSRange subStr_pic = [_pictureUrl rangeOfString:@"sp00000"];
    NSRange subStrs_pic = [_pictureUrl rangeOfString:@"ss0000"];
    if (subStrs_pic.location != NSNotFound) {
        [_pictureUrl replaceCharactersInRange:subStrs_pic withString:[NSString stringWithFormat:@"ss%@", specitem]];
    }
    if (subStr_pic.location != NSNotFound) {
        [_pictureUrl replaceOccurrencesOfString:@"sp00000" withString:[NSString stringWithFormat:@"sp%@", carId] options:NSCaseInsensitiveSearch range:NSMakeRange(0, [_pictureUrl length])];
    }

    //界面三网址拼接
    
    [_equipMentUrl replaceOccurrencesOfString:@"s00000" withString:[NSString stringWithFormat:@"s%@", carId] options:NSCaseInsensitiveSearch range:NSMakeRange(0, [_equipMentUrl length])];
    
    //界面四网址拼接
    [_praiseUrl replaceOccurrencesOfString:@"sp00000" withString:[NSString stringWithFormat:@"sp%@", carId] options:NSCaseInsensitiveSearch range:NSMakeRange(0, [_praiseUrl length])];
    
    [self connect_Sell:_urlStr];
    [self connect_SellDetail:_detailUrl];
}

#pragma mark -
#pragma mark 汽车详情页网络请求
- (void)connect_SellDetail:(NSString *)url
{
    url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [NetUrl connect:url parmater:nil Block:^(NSData *data) {
        
        NSDictionary *Sellcar_Dictionary = (NSDictionary *)data;
        NSMutableDictionary *sellDic = [Sellcar_Dictionary objectForKey:@"result"];
        NSMutableArray *sellCar = [[Sellcar_Dictionary objectForKey:@"result"] objectForKey:@"paramlist"];
        
        _moDel.logo = [sellDic objectForKey:@"logo"];
        _moDel.car_body = [[sellCar objectAtIndex:0] objectForKey:@"value"];
        _moDel.car_drive = [[sellCar objectAtIndex:1] objectForKey:@"value"];
        _moDel.car_speed = [[sellCar objectAtIndex:2] objectForKey:@"value"];
        _moDel.car_price = [[sellCar objectAtIndex:3] objectForKey:@"value"];
        _moDel.car_minprice = [[sellCar objectAtIndex:4] objectForKey:@"value"];
         [_image sd_setImageWithURL:[NSURL URLWithString:_moDel.logo] placeholderImage:[UIImage imageNamed:@"Loading.png"]];
        [_tableView reloadData];
    }];
}


#pragma mark -
#pragma mark 卖家网络请求

- (void)connect_Sell:(NSString *)url
{
    [_tableViewArray removeAllObjects];
    url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [NetUrl connect:url parmater:nil Block:^(NSData *data) {
        
        NSDictionary *Sellcar_Dictionary = (NSDictionary *)data;
        NSMutableArray *sellCar = [[Sellcar_Dictionary objectForKey:@"result"] objectForKey:@"dealerlist"];
        //循环获取数据 存入model 存入数组中
        for (NSMutableDictionary *dic in sellCar) {
            DealerListModel *moDel = [[DealerListModel alloc] init];
            moDel.shortName = [dic objectForKey:@"shortname"];
            moDel.addRess = [dic objectForKey:@"address"];
            moDel.phone = [dic objectForKey:@"phone"];
            moDel.scopename = [dic objectForKey:@"scopename"];
            moDel.orderrange = [dic objectForKey:@"orderrange"];
            moDel.saleprice = [dic objectForKey:@"saleprice"];
            moDel.loworminperce = [dic objectForKey:@"loworminprece"];
            moDel.ion = [dic objectForKey:@"lon"];
            moDel.lat = [dic objectForKey:@"lat"];
            [_tableViewArray addObject:moDel];
            [moDel release];
        }
        [_tableView reloadData];
    }];
}

#pragma mark -
#pragma mark 图片页网络请求
- (void)connect_Picture:(NSString *)url
{
    [_pictureArray removeAllObjects];
    [NetUrl connect:url parmater:nil Block:^(NSData *data) {
        
        NSDictionary *picture_Dictionary = (NSDictionary *)data;
        NSMutableArray *picDic = [[picture_Dictionary objectForKey:@"result"] objectForKey:@"defaultpiclist"];
        
        [_pictureArray addObjectsFromArray:picDic];
        [_pictureView reloadData];
    }];
}

#pragma mark -
#pragma mark 配置页网络请求

- (void)connect_Equipment:(NSString *)url
{
    [_equipMentArray removeAllObjects];
    [NetUrl connect:url parmater:nil Block:^(NSData *data) {
        
        NSDictionary *picture_Dictionary = (NSDictionary *)data;
        NSMutableDictionary *picDic = [picture_Dictionary objectForKey:@"result"];
        //便利数组取出paramitems
    for (NSMutableDictionary *all_dic in [picDic objectForKey:@"paramitems"]) {
            
        ParamitemsEquipMent *paramitem = [[ParamitemsEquipMent alloc] init];
        paramitem.type = [all_dic objectForKey:@"itemtype"];
        //取出name value
        for (NSMutableDictionary *dic in [all_dic objectForKey:@"items"]) {
            EquipMentModel *equip = [[EquipMentModel alloc] init];
            equip.name = [dic objectForKey:@"name"];
            equip.value = [[[dic objectForKey:@"modelexcessids"] firstObject] objectForKey:@"value"];
            [paramitem.items addObject:equip];
            [equip release];
        }
        [_equipMentArray addObject:paramitem];
        [paramitem release];
    }
        
    for (NSMutableDictionary *all_dic in [picDic objectForKey:@"configitems"]) {
                
       ParamitemsEquipMent *paramitem = [[ParamitemsEquipMent alloc] init];
       paramitem.type = [all_dic objectForKey:@"itemtype"];
        // 数据存入model
            for (NSMutableDictionary *dic in [all_dic objectForKey:@"items"]) {
                    EquipMentModel *equip = [[EquipMentModel alloc] init];
                    equip.name = [dic objectForKey:@"name"];
                    equip.value = [[[dic objectForKey:@"modelexcessids"] firstObject] objectForKey:@"value"];
                    [paramitem.items addObject:equip];
                    [equip release];
                }

            
        [_equipMentArray addObject:paramitem];
        [paramitem release];
        }
        [_equipMentView reloadData];
    }];
}

#pragma mark -
#pragma mark 评分页网络请求

- (void)connect_Praise:(NSString *)url
{
    [_praiseArray removeAllObjects];
    [NetUrl connect:url parmater:nil Block:^(NSData *data) {
        
        NSDictionary *picture_Dictionary = (NSDictionary *)data;
        NSMutableArray *picDic = [[picture_Dictionary objectForKey:@"result"] objectForKey:@"grades"];
        
        for (NSMutableDictionary *dic in picDic) {
            
            NSMutableArray *array = [[NSMutableArray alloc] init];
            [array addObject:dic];
            
        }
        
        //第四页 耗油量 评分
        
        [_praiseArray addObjectsFromArray:picDic];
        [_praiseView reloadData];
        [_praiseLabel_prt setText:[NSString stringWithFormat:@"%@ 升/百公里", [[picture_Dictionary objectForKey:@"result"] objectForKey:@"fuelconsumption"]]];
        [_praiseLabel_per setText:[NSString stringWithFormat:@"%@ 人参与", [[picture_Dictionary objectForKey:@"result"] objectForKey:@"peoplenum"]]];
        if ([_praiseArray count] == 0 ) {
            [_label setText:@"暂无评分"];
        } else {
            [_label setText:@""];
        }
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
